<?php
	include ("include/header.php");
?>

<script type="text/javascript">
function checkform()
		{
			var userLength=document.getElementById("idUser").value.length;
			var passLength=document.getElementById("idPass").value.length;
			var emailLength=document.getElementById("idEmail").value.length;
			var nameLength=document.getElementById("idName").value.length;
			var surnameLength=document.getElementById("idSurname").value.length;
			var pCodeLength=document.getElementById("idPcode").value.length;		
			var addressLength=document.getElementById("idAddress").value.length;
			var repassValue=document.getElementById("idrepass").value;
			var passValue=document.getElementById("idPass").value;	
					
		
		if(passLength==0)
			{
				alert("กรุณากรอก Password ด้วยครับ");
				return false;
			}
		
		if(userLength==0)
			{
				alert("กรุณากรอก Username ด้วยครับ");
				return false;
			}
		
		if(emailLength==0)
			{
				alert("กรุณากรอก email ด้วยครับ");
				return false;
			}
		if(nameLength==0)
			{
				alert("กรุณากรอก name ด้วยครับ");
				return false;
			}
		if(surnameLength==0)
			{
				alert("กรุณากรอก surname ด้วยครับ");
				return false;
			}
		if(pCodeLength==0)
			{
				alert("กรุณากรอก Personal Code ด้วยครับ");
				return false;
			}
		if(addressLength==0)
			{
				alert("กรุณากรอก Address ด้วยครับ");
				return false;
			}
		if(repassValue!=passValue)
			{
				alert("Confirm Password Not Match");
				return false;
			}
				
		}
</script>

<script type="text/javascript">
function validateUser()
		{
		
			$.get("registeraction.php",{username:$('#idUser').val()},function(dataresponse)
			{
				$('#usernameMessage').html(dataresponse);
				//alert(dataresponse);
			});
		}
</script>
<div id="form_container">
<form id="form1" name="RegisterForm" method="post" action="registeraction.php" class="niceform" onsubmit="return checkform();" enctype="multipart/form-data">
<fieldset>
    	<legend>ลงทะเบียนสมาชิก</legend>
  <dl>  
    <dt><label for="username">Username</label></dt>
    <dd><input type="text" name="username" id="idUser" onchange="validateUser();"/> <span id="usernameMessage"> </span> </dd>
  </dl>
  
  <dl>
    <dt><label for="password">Password</label></dt>
    <dd><input type="password" name="password" id="idPass" /></dd>
  </dl>
  
  <dl>
    <dt><label for="Confirm_password">Re-Password</label></dt>
    <dd><input type="password" name="confPassword" id="idrepass" /></dd>
  </dl>
  
  <dl>
    <dt><label for="email">E-Mail</label>
    <dd><input type="text" name="email" id="idEmail" /></dd>
  </dl>
  
  <dl>
    <dt><label for="name">Name</label></dt>
    <dd><input type="text" name="name" id="idName" /></dd>
  </dl>
  
  <dl>
    <dt><label for="surname">Surname</label></dt>
    <dd><input type="text" name="surname" id="idSurname" /></dd>
  </dt>
  
  <dl>
    <dt><label for="title">Title</label></dt>
      <dd><label for="mr">
         <input type="radio" name="title" id="RadioGroup2_0" value="นาย" checked="checked" />
        นาย</label>
        <label for="miss">
         <input type="radio" name="title" value="นาง" id="RadioGroup2_1" />
         นาง</label>
        <label for="Mrs">
         <input type="radio" name="title" value="นางสาว" id="RadioGroup2_2" />
         นางสาว</label></dd>
   </dl>
  
  <dl>
    <dt><label for="personal_code">Personal Code</label></dd>
    <dd><input type="text" name="personalCode" id="idPcode" /></dd>
  </dl>
  
  
  <dl>
    <dt><label for="address">Address</label></dt>
    <dd><label for="textarea"></label>
      <textarea name="address" id="idAddress" cols="45" rows="5"></textarea></dd>
  </dl>
  
  
  
  <dl>
    <dt><label for="image_file">Image file</label></dt>
    <dd><input type="file" name="user_image" id="textfield4" /></dd>
  </dl>
</fieldset>
<fieldset class="register">
	<input type="submit" name="add" id="button" value="register" />
</fieldset>
</form>
</div>
<?php
	include ("include/footer.php");
?>
